package com.controller;


import com.github.pagehelper.PageInfo;
import com.pojo.Sitetopic;
import com.service.SiteService;
import com.vo.Result;
import com.vo.SiteTopicVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/Site")
public class SiteTopicController {
    @Resource
    private SiteService siteService;

    private Integer topicid;

    @RequestMapping("/sitetopic/index")
    public String toSite(Integer id){
        topicid=id;
        return "/Site/SiteTopic";
    }

    @RequestMapping("/sitetopic/show")
    @ResponseBody
    public Result selectSitetopic(@RequestBody SiteTopicVo siteTopicVo){
        siteTopicVo.setTopicid(topicid);
        PageInfo<Sitetopic> sitetopicPageInfo = siteService.selectAllSitetopic(siteTopicVo);
        return Result.success(sitetopicPageInfo);
    }

    @RequestMapping("/sitetopic/update")
    @ResponseBody
    public Result update(Sitetopic sitetopic){
        try {
            sitetopic.setSiteid(topicid);

            siteService.updateSiteTopic(sitetopic);
            return Result.success("修改成功");
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail("修改失败");
        }
    }
    @RequestMapping("/sitetopic/add")
    @ResponseBody
    public Result add(Sitetopic sitetopic){
        try {
            sitetopic.setSiteid(topicid);

            siteService.addSiteTopic(sitetopic);
            return Result.success("添加成功");
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail("添加失败");
        }
    }

    @RequestMapping("/sitetopic/delete")
    @ResponseBody
    public Result delete(Integer id){
        try {
            siteService.deleteSiteTopicbyid(id);
            return Result.success("删除成功");
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail("删除失败");
        }
    }


}
